package com.example.su_shi_tan_core.db

import com.example.su_shi_tan_bas_lib.preference.Preference
import com.example.su_shi_tan_core.constant.CURRENT_SIGNED_UP_KEY
import com.example.su_shi_tan_core.constant.SignUserBeanHolder

class LogInTokenManager private constructor() {

    companion object {

        val tokenManager by lazy { LogInTokenManager() }

    }

    fun saveLogInToken(token: String) {
        Preference.HOLDER.addCustomAppProfile(CURRENT_SIGNED_UP_KEY, token)
    }

    fun getLogInToken() = Preference.HOLDER.getCustomAppProfile(CURRENT_SIGNED_UP_KEY)

    fun haveSignedIn(): Boolean {
        val logInToken = getLogInToken()
        if (logInToken == null || logInToken.isEmpty()) {
            return false
        }
        return true
    }

    fun signOutUserInfoWrapper() {
        UserInfoBeanHolder.onDelete()
        SignUserBeanHolder.onSave(null)
        Preference.HOLDER.removeCustomAppProfile(CURRENT_SIGNED_UP_KEY)

    }
}